package com.qudian.pay.log.aop;

import org.aopalliance.intercept.MethodInvocation;
import com.qudian.pay.core.aop.BaseInterceptor;
import com.qudian.pay.core.diagnostic.Profiler;

/**
 * @Description: 自定义层性能日志拦截
 * @ClassName: PerformanceDaoInterceptor
*
 * @date 2015年11月17日 下午10:32:07
 */
public class PerformanceCustomInterceptor extends BaseInterceptor {
	
	private String layerName = "undefined";
	
	@Override
	public Object bizInvoke(MethodInvocation invocation) throws Throwable {
		StringBuilder builder = new StringBuilder("Invoking " + layerName + " method: ");
		builder.append(invocation.getMethod().getDeclaringClass().getName()).append(".").append(invocation.getMethod().getName());
		Profiler.enter(builder.toString());
		try {
			return invocation.proceed();
		} finally {
			Profiler.release();
		}
	}
	
	public void setLayerName(String layerName) {
		this.layerName = layerName;
	}
}
